<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    
    <title>邮箱设置</title>
    
	<link rel="stylesheet" type="text/css" href="<%=path%>/JS/extjs/resources/css/ext-all.css"/>
	<script type="text/javascript" src="<%=path%>/JS/extjs/adapter/ext-base.js"></script>
	<script type="text/javascript" src="<%=path%>/JS/extjs/ext-all.js"></script>
	<script type="text/javascript" src="<%=path%>/JS/extjs/ext-lang-zh_CN.js" charset="utf-8"></script>
	<script type="text/javascript" src="<%=path%>/JS/jquery-1.7.2.js"></script>

  </head>
  
  <body>
  
 	<script type="text/javascript">
 		function InitMain(){
 			//Ext.form.Field.prototype.msgTarget = 'side';
			var formPanel = new Ext.FormPanel({
				id:"formPanel",
					frame:true,
					x:40,
		            y:30,
					//title:"用户信息",
					labelAlign:"right",
					labelWidth: 85,
			        width:360,
			        height:400,
			        border:false,
			        waitMsgTarget: true,
			        region:"west",

			        // configure how to read the XML Data
			        reader : new Ext.data.JsonReader({
			        	root:'mailInfoList'
				        }, [
						{name:'id'}, 
			            {name:'mailServerHost'}, 
			            {name:'mailServerAddress'},
			            {name:'mailServerPassword'}, 
			            {name:'isAvailable'}
			            ]),

			        // reusable eror reader class defined at the end of this file*/
			       // errorReader: new Ext.form.XmlErrorReader(),

			        items: [
			            new Ext.form.FieldSet({
			               	title: '服务邮箱',
			               	width:340,
			               	autoHeight: true,
			                defaultType: 'textfield',
			                items: [{
			                        fieldLabel: 'id',
			                        emptyText: '',
			                        name: 'id',
			                        allowBlank: true,
			                        hidden   : true,//隐藏
			                        width:190
			                    },{
			                        fieldLabel: '邮箱主机',
			                        emptyText: '如stam.qq.com',
			                        name: 'mailServerHost',
			                        allowBlank: false,
			                        width:190
			                    }, {
			                        fieldLabel: '邮箱地址',
			                        emptyText:'如123456@qq.com',
			                        name: 'mailServerAddress',
			                        allowBlank: false,
			                        vtype:"email",
			                        width:190
			                    }, {
			                        fieldLabel: '邮箱密码',
			                        emptyText:'请输入密码',
			                        name: 'mailServerPassword',
			                        //inputType: 'password',
			                        allowBlank: false,
			                        width:190
			                    },new Ext.form.ComboBox({
			                        fieldLabel: '是否可用',
			                        hiddenName:'isAvailable',
			                        allowBlank:false,
			                        blankText:'不能为空',
			                        store: new Ext.data.ArrayStore({
			                            fields: ['abbr', 'isAvailable'],
			                            data : [
					                            [0,'否'],
					                            [1,'是']] 
			                        }),
			                        valueField:'abbr',
			                        displayField:'isAvailable',
			                        typeAhead: true,
			                        mode: 'local',
			                        triggerAction: 'all',
			                        selectOnFocus:true,
			                        hidden   : true,//隐藏
			                        width:190
			                    })
			                ]
			            })
			        ]
			});

			formPanel.form.load({url:'${pageContext.request.contextPath}/emailServerInfoAction!getEmailServerInfo.action'});

			var formToolbar = new Ext.Toolbar({
				id:"formToolbar",
				border:false,
				items:[
						{
							id:"savebtn",
						    text:"保存",
						    handler:function(){
						    var formvalue = Ext.util.JSON.encode(formPanel.getForm().getValues());
							if(formPanel.getForm().isValid()){
								formPanel.getForm().submit({
									 	url : '${pageContext.request.contextPath}/emailServerInfoAction!saveEmainServerInfo.action',
									 	contentType: "application/x-www-form-urlencoded; charset=utf-8",
									 	params:{formStr:encodeURIComponent(formvalue)},
				                     	success : function(response, options) {
											Ext.Msg.alert('提示', options.result.data);
			                        		//alert(action.result.data);
				                        },
				                        failure : function(form, action) {
				                        	Ext.Msg.alert('提示', '保存失败！');
				                        },
				                        submitEmptyText: false,
				                        waitMsg : '正在保存数据，稍后...'
								});
							}else{
								Ext.Msg.alert("提示","输入有错误");
							}
							}
						},{
							id:'reset',
						    text:'重置',
						    xtype:"tbbutton",
						    cls: 'x-btn-text-icon',
						    handler:function(){
								Ext.getCmp("formPanel").form.load({url:'${pageContext.request.contextPath}/emailServerInfoAction!getEmailServerInfo.action'});
							 }
						}
						]
			});

			var centerPanel = new Ext.Panel({
				id:"centerPanel",
				//title:"邮箱设置 ",
				layout:"fit",
				width:"100%",
				//region:"center",
				//html:"邮箱设置",
				tbar:[formToolbar],
				items:[
					formPanel
						]
			});

			var viewport = new Ext.Viewport({
				id:"viewport",
				layout:"fit",
				items:[
						centerPanel
						]
			});
 	 		
 		}

 		Ext.onReady(InitMain);
 	
 	
 	</script>
  
  </body>
</html>
